
<link rel="stylesheet" href="/static/plugins/js/form-design/css/index.css?ts=${.ts}" />
<style>

</style>
<div class="container-fluid" id="app">
        <script src="/static/plugins/js/form-design/js/index.js?ts=${.ts}"></script>
        <script>
            $(function () {
                let app={
                    form:JSON.parse("${.form}"),
                    getTextConfig:function (data){
                          return {
                              "placeholder":data.placeholder,
                              "check":data.check,
                              "required":data.required,
                          }
                    },
                    getMultipleConfig:function (data){
                        return {
                            "placeholder":data.placeholder,
                            "height":data.height,
                            "required":data.required,
                        }
                    },
                    getRadioConfig:function (data){
                        return {
                            "rand":data.rand,
                            "options":data.options,
                            "required":data.required,
                        }
                    },
                    getCheckboxConfig:function (data){
                        return {
                            "rand":data.rand,
                            "options":data.options,
                            "required":data.required,
                        }
                    },
                    getSelectConfig:function (data){
                        return {
                            "rand":data.rand,
                            "options":data.options,
                            "required":data.required,
                        }
                    },
                    getDateConfig:function (data){
                        return {
                            "required":data.required,
                        }
                    },

                };
                $.formDesign.build({ el: '#app', height: '600px',type:"design",
                    saveForm:function (data){

                          let req={

                              form_id:parseInt("${.id}"),
                              config:JSON.stringify(data.config),
                              topics:[],

                          };
                          data.topics.forEach(function (topic){
                               let curTopic={
                                   "id":topic.id,
                                   "uuid":topic.uuid,
                                   "type":topic.type,
                                   "name":topic.name,
                               }
                              switch (topic.type){
                                  case "text":
                                      curTopic.config=app.getTextConfig(topic);
                                      break;
                                  case "multiple":
                                      curTopic.config=app.getMultipleConfig(topic);
                                      break;
                                  case "date":
                                      curTopic.config=app.getDateConfig(topic);
                                      break;
                                  case "select":
                                      curTopic.config=app.getSelectConfig(topic);
                                      break;
                                  case "radio":
                                      curTopic.config=app.getRadioConfig(topic);
                                      break;
                                  case "checkbox":
                                      curTopic.config=app.getCheckboxConfig(topic);
                                      break;
                              }


                              if(curTopic.config){
                                  curTopic.config=JSON.stringify(curTopic.config)
                                  req.topics.push(curTopic);
                              }




                          });
                           //保存
                        doPost("/admin/form/savedesign",req,function (data){

                            //跳转到列表页
                            window.location.href="/admin/form/index?tag=${.tag}&ts=${.ts}";

                        })


                    },
                    "data":app.form
                })
            });
        </script>
</div>
